﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


namespace Biblioteca.Usuario
{
    public partial class Logueo : Form
    {
        ClassDB GenClassBD;
        //ClassBD GenClassBD;

        //esto va si o si...
        private static Logueo formInstancia = null;
        BindingSource miBS;
        public static Logueo Instancia()
        {
            if ((formInstancia == null) || (formInstancia.IsDisposed == true))
            {
                formInstancia = new Logueo();
            }
            formInstancia.BringToFront();
            return formInstancia;
        }


        public Logueo()
        {
            InitializeComponent();
            miBS = new BindingSource();
            GenClassBD = new ClassDB();
            textBoxPassword.PasswordChar = '*';

        }

        private void Logueo_Load(object sender, EventArgs e)
        {
            this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
            this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBoxNombre.Text = "";
            textBoxApellido.Text = "";
            textBoxPassword.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxNombre.Text != "" && textBoxPassword.Text != "")
            {
                string controlUsuario = Convert.ToString(GenClassBD.ConsultaSimple("Select * from Usuario where nombre = '" + textBoxNombre.Text + "' and apellido = '" + textBoxApellido.Text + "'"));
                if (controlUsuario == "")
                {
                    MessageBox.Show("Los Datos del Usuario son Incorrectos", "Usuario No Encontrado", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    string controlPassword = Convert.ToString(GenClassBD.ConsultaSimple("Select * from Usuario where contraseña = '" + textBoxPassword.Text + "' and estado = '" + labelEstado.Text + "'" ));
                    if (controlPassword == "")
                    {
                        MessageBox.Show("La contraseña es Incorrecta", "Contraseña Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    { 
                     
                        Principal main = new Principal();
                        //Principal main = Principal.Instancia();
                         this.Hide();
                        main.Show();
                       

                    }
                }

            }

        }   
    }
}
